﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Abp.Domain.Repositories;
using KelonProud.Linq;
using KelonProud.TableManagement.Domain;

namespace KelonProud.TableManagement.Managers
{
    public class TableCategoryManager : KelonProudDomainService<TableCategory>
    {
        public TableCategoryManager(IRepository<TableCategory, int> manageRepository) : base(manageRepository)
        {
        }

        protected override void VerifySaveOrUpdateError(TableCategory tableCategory)
        {
            if(Query.Any(a=>a.Id!=tableCategory.Id&&a.Name==tableCategory.Name&&a.ParentId==tableCategory.ParentId))
                throw  new Exception("同一节点下分类名称重复");

            if (Query.Any(a => a.Id != tableCategory.Id && a.Code == tableCategory.Code && a.ParentId == tableCategory.ParentId))
                throw new Exception("同一节点下分类编码重复");

         
        }
    }
}
